/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.inventory;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "commodity_has_commodity")
@NamedQueries({
    @NamedQuery(name = "CommodityHasCommodity.findAll", query = "SELECT c FROM CommodityHasCommodity c"),
    @NamedQuery(name = "CommodityHasCommodity.findByAmount", query = "SELECT c FROM CommodityHasCommodity c WHERE c.amount = :amount")})
public class CommodityHasCommodity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "amount")
    private Integer amount;
    @JoinColumn(name = "subcommodity_id", referencedColumnName = "id")
    @ManyToOne
    private Commodity subcommodity;
    @JoinColumn(name = "commodity_id", referencedColumnName = "id")
    @ManyToOne
    private Commodity commodity;

    public CommodityHasCommodity() {
    }

    public CommodityHasCommodity(Commodity commodity, Commodity subcommodity) {
        this.commodity= commodity;
        this.subcommodity = subcommodity;
        amount = 0;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Commodity getCommodity() {
        return commodity;
    }

    public void setCommodity(Commodity commodity) {
        this.commodity = commodity;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commodity)) {
            return false;
        }
        CommodityHasCommodity other = (CommodityHasCommodity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.retail.CommodityHasCommodity[id=" + id + "]";
    }

    /**
     * @return the subcommodity
     */
    public Commodity getSubcommodity() {
        return subcommodity;
    }

    /**
     * @param subcommodity the subcommodity to set
     */
    public void setSubcommodity(Commodity subcommodity) {
        this.subcommodity = subcommodity;
    }

    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }
}
